import bodyParser from 'body-parser'
import expressWinston from './middleware/expressWinston'
import redirect from './middleware/redirect'
import upload from './middleware/upload'
import ErrorHandler from './middleware/errorHandler'
import PayHandler from './middleware/payHandler'
import route from './controller/route'
import wechatRoute from './controller/wechat.route'
import Express from 'express'
const app = Express();
const {Nuxt, Builder} = require('nuxt');
const session = require('express-session');
// Sessions 来创建 req.session
app.use(session({
  secret: 'super-secret-key',
  resave: false,
  saveUninitialized: false,
  cookie: {maxAge: 3*60*60*1000}
}));



// Body parser，用来封装 req.body
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json()); 
app.use(expressWinston);
// app.use(redirect);
app.use(PayHandler);
app.use("/api",upload);
app.use("/api",route);
app.use("/api/wechat",wechatRoute);
app.use(ErrorHandler);

// const config = require('../nuxt.config.js');
// const isProd = process.env.NODE_ENV === 'production'
// const nuxt = new Nuxt(config)
// if (!isProd) {
//   const builder = new Builder(nuxt)
//   builder.build()
// }

// app.use(nuxt.render);

export default app;
